﻿using hcrainface.Dto;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using testface;
using static System.Net.Mime.MediaTypeNames;

namespace hcrainface.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class HcrainFaceController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };

        private readonly ILogger<HcrainFaceController> _logger;

        public HcrainFaceController(ILogger<HcrainFaceController> logger)
        {
            Face.FaceInt();
            _logger = logger;
        }

        [HttpPost("addface")]
        public string addface(FaceimgInfo p)
        {
            // 人脸库示例
            FaceManager manager = new FaceManager();
            //  人脸注册
            var re= manager.test_user_add(p.getImgPath(), p.SysUserId, p.UserName);
           lock("hechaoloaddb") FaceCompare.load_db_face();
            return re;

        }
        [HttpPost("searchface")]
        public string searchface1(FaceimgInfo p)
        {
            FaceCompare comp = new FaceCompare();
            return comp.test_identify_with_all(p.getImgPath());
        }
        [HttpGet("addface1")]
        public string addface1(string p)
        {
            // 人脸库示例
            FaceManager manager = new FaceManager();
            //  人脸注册
            return manager.test_user_add(p, "001", "何潮");

        }
        [HttpGet("searchface1")]
        public string searchface1(string p)
        {
            FaceCompare comp = new FaceCompare();
            return comp.test_identify_with_all(p);
        }

        [HttpGet("test1")]
        public string imgtest()
        {

            Thread t2 = new Thread(new ThreadStart(Face.Main1112));

            //ThreadC tc = new ThreadC();
            //Thread t3 = new Thread(new ThreadStart(tc.c_run));

            // t1.Start();
            t2.Start();
            Thread t3 = new Thread(new ThreadStart(Face.Main1113));

            //ThreadC tc = new ThreadC();
            //Thread t3 = new Thread(new ThreadStart(tc.c_run));

            // t1.Start();
            t3.Start();

            // Face.Main1112("D:\\alva\\track\\hcrainface\\hcrainface\\bin\\images\\6.jpg");

            return "1233";
        }
        [HttpGet("test")]
        public IEnumerable<WeatherForecast> Get()
        {
            var rng = new Random();
            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = rng.Next(-20, 55),
                Summary = Summaries[rng.Next(Summaries.Length)]
            })
            .ToArray();
        }
    }
}
